import requests
from bs4 import BeautifulSoup
import re
import os

url = 'https://www.shejidaren.com/dribbble-beautiful-ui-design-last-half-of-2012.html'
response = requests.get(url)                        # 发送请求
html = response.text                                # 网页源码
soup = BeautifulSoup(html,'lxml')                   # BeautifulSoup解析，feature = 'parser'或'lxml'
# 直接获取标签内容
label_p = soup.p
label_a = soup.find_all('a')
label_li_relatedbox = soup.find('li',{'class':'related_box'})  # 利用CSS的规律定位内容具体到类
for each in label_a:                                  # 打印所有的链接
    try:
        print(each['href'])                           # 直接索引key提取
    except KeyError:
        pass
# 获取图片链接
# 正则表达式1：(.*?)代表任何字符串
imagelinks = soup.find_all('img',{'src':re.compile('.*?\.')})  # 后面字典的key是=之前的名称，value是=之后的值,根据实际问题后面的字典可以不要
imagelinks = [each['src']for each in imagelinks]      # 直接索引key提取
# 正则表达式2：.*代表任何后缀字符串
imagelinks2 = soup.find_all('img',{'src':re.compile('https://www.shejidaren.*')})
imagelinks2 = [each['src']for each in imagelinks2]    # 直接索引key提取

print(imagelinks)